﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.CompositionRootTypeExtractor
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal class CompositionRootTypeExtractor : ITypeExtractor
  {
    private readonly ICompositionRootAttributeExtractor compositionRootAttributeExtractor;

    public CompositionRootTypeExtractor(
      ICompositionRootAttributeExtractor compositionRootAttributeExtractor)
    {
      this.compositionRootAttributeExtractor = compositionRootAttributeExtractor;
    }

    public Type[] Execute(Assembly assembly)
    {
      CompositionRootTypeAttribute[] attributes = this.compositionRootAttributeExtractor.GetAttributes(assembly);
      return attributes.Length != 0 ? ((IEnumerable<CompositionRootTypeAttribute>) attributes).Select<CompositionRootTypeAttribute, Type>((Func<CompositionRootTypeAttribute, Type>) (a => a.CompositionRootType)).ToArray<Type>() : assembly.DefinedTypes.Where<TypeInfo>((Func<TypeInfo, bool>) (t => !t.IsAbstract && typeof (ICompositionRoot).GetTypeInfo().IsAssignableFrom(t))).Cast<Type>().ToArray<Type>();
    }
  }
}
